<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');
if($_POST['act']=='add'){
		$pows=$_POST['pows'];
		$arr['rolename']=trim($_POST['rolename']);
		
		$arr['status']=$_POST['status'];
		
		if(empty($arr['rolename'])) show_automsg('请输入角色名称',$GLOBALARR['curl'],1);
		if(empty($pows)) show_automsg('请为角色至少指派一个权限',$GLOBALARR['curl'],1);
		//if($edid==1) show_automsg('该角色禁止编辑',$GLOBALARR['curl'],1);
		$max='';
		foreach ($pows as $k => $v) {
			$s=getmenu($GLOBALARR['menu'],$v,1);
			if(!strstr($max,$s)){
				$max.="$s,";
			}
		}
		$arr['privilege_cn']=$max;
		$arr['privilege_en'] = implode(',',$pows);
		
		$sql1="select * from ld_privilege where rolename= '".$arr['rolename']."'";
		
		$db->query($sql1,2);
		
		if(!empty($db->rs)){
			 show_automsg('角色名称已经存在',$GLOBALARR['curl'],1);
		}
		
		$sql = getinsertsql($arr,'ld_privilege');
		
		$db->sitedbexec($sql);
		record_log('添加角色:'.$arr['rolename']);
		show_automsg('添加角色成功！',YMCURL.'rolelist');
		
}



echo '<h3>角色添加</h3>';
echo '<div class="main-r-body"><form method="post" action="'.geturl().'">
		<div class="main-r-item"><a href="'.YMCURL.'rolelist" class="thabtn">返回角色列表</a><input type="submit" class="thabtn" value="添加"></div>
		<input type="hidden" name="act" value="add">';
echo '<table class="tregtab ttab">';
echo '	<tr>
			<td class="wdb20 alignr paddingr">角色名称</td>
			<td class="alignl paddingl"><input type="text" name="rolename" value="" class="thconfig wd400"></td>
		</tr>';
echo '	<tr>
			<td class="wdb20 alignr paddingr">状态</td>
			<td class="alignl paddingl">'.tradio(array('status',$db->rs['status']),2).'</td>
		</tr>';		
echo '	<tr>
			<td class="wdb20 alignr paddingr" valign="top" >指派权限</td>
			<td class="alignl paddingl">';
			$i=0;
			foreach ($GLOBALARR['menu'] as $kr => $vr) {
			$i++;
			echo '<ul class="ulpower"><li style="width:13%;color:#333;"><label><input type="checkbox" onclick="javascript:checkbox(this,\'a'.$i.'\')" style="vertical-align:middle">'.$kr.'</label></li><li style="width:82%;border-bottom:1px dotted #535548">';
				foreach ($vr as $k => $v) {
					echo '<label><input type="checkbox" name="pows[]" value="'.$v[0].'" class="a'.$i.'" '.getstrval(array($db->rs['privilege_en'],$v[0],'checked','')).'>&nbsp;'.$k.'</label>&nbsp;';
				}
			echo '</ul>';				
			}		
echo '		</td>
		</tr>';		
echo '</table>';
echo '</form></div>';		

?>